<template>
  <div class="index">
    <div class="left">
      <h2>WR管理系统</h2>
      <el-menu
        router
        active-text-color="#ffd04b"
        background-color="#475164"
        default-active="2"
        text-color="#fff"
      >
        <el-sub-menu index="/group_config">
          <template #title>
            <el-icon><Lock /></el-icon>
            <span>权限管理</span>
          </template>
          <el-menu-item index="/group_config">用户组</el-menu-item>
          <el-menu-item index="/permission_config">组权限设置</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="/device_config">
          <template #title>
            <el-icon><Monitor /></el-icon>
            <span>设备管理</span>
          </template>
          <el-menu-item index="/device_config">设备配置</el-menu-item>
          <el-menu-item index="/device_control">设备控制</el-menu-item>
        </el-sub-menu>
      </el-menu>
    </div>
    <div class="right">
      <div class="top">
        <el-menu
          router
          :ellipsis="false"
          mode="horizontal"
          background-color="#475164"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <el-menu-item index="/home"
            ><el-icon><House /></el-icon>首页</el-menu-item
          >
          <el-menu-item index=""
            ><el-icon><Bell /></el-icon>通知</el-menu-item
          >
          <el-sub-menu index="/information">
            <template #title
              ><el-icon><User /></el-icon>个人中心</template
            >
            <el-menu-item index="/information">个人信息</el-menu-item>
            <el-menu-item index="/changepwd">修改密码</el-menu-item>
            <el-menu-item index="" @click="exit">退出登录</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </div>
      <div class="content">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted } from "vue";
import { Lock, User, Monitor, House, Bell } from "@element-plus/icons-vue";
import { useUserStore } from "../store/user";
import { useRouter } from "vue-router";
import { ElMessageBox } from "element-plus";
let useUser = useUserStore();
let Router = useRouter();
onMounted(() => {
  if (!useUser.user.isLogin) {
    Router.push("/login");
  }
});

//退出系统
let exit = () => {
  ElMessageBox.confirm("确认退出系统？", "系统提示", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      sessionStorage.clear();
      useUser.clearUser();
      Router.push("/Login");
    })
    .catch(() => {});
};
</script>

<style scoped lang="scss">
.index {
  width: 100vw;
  height: 100vh;
  display: flex;
  .left {
    width: 200px;
    background-color: #475164f5;
    color: #fff;
    .el-menu {
      border-right: none;
    }
    h2 {
      text-align: center;
      font-size: 25px;
      font-family: zhou;
      height: 60px;
      line-height: 60px;
    }
  }
  .right {
    flex: 1;
    display: flex;
    flex-direction: column;
    .top {
      height: 60px;
      background-color: #475164f5;
      color: #fff;
      display: flex;
      justify-content: flex-end;
      .el-menu {
        border-bottom: none;
      }
    }
    .content {
      flex: 1;
      padding: 5px;
    }
  }
}
</style>
